﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AGVUppCom
{
    public partial class FrmLand : Form
    {
        public FrmLand()
        {
            InitializeComponent();
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                TboxName.Enabled = false;
                TboxPassWord.Enabled = false;
            }
            else
            {
                TboxName.Enabled = true;
                TboxName.Text = "admin";
                TboxPassWord.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                Form1 frmMain = new Form1(0);
                frmMain.Show();
                this.Hide();
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                if (string.IsNullOrEmpty(TboxName.Text.Trim()) || string.IsNullOrEmpty(TboxPassWord.Text.Trim()))
                {
                    return;
                }
                else if (TboxName.Text.Trim() != "admin")
                {
                    MessageBox.Show("用户名错误");
                    return;
                }
                else if (TboxPassWord.Text.Trim().ToLower() != "123")
                {
                    MessageBox.Show("密码错误");
                    return;
                }
                else
                {
                    Form1 frmMain = new Form1(1);
                    frmMain.Show();
                    this.Hide();
                }
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                if (string.IsNullOrEmpty(TboxName.Text.Trim()) || string.IsNullOrEmpty(TboxPassWord.Text.Trim()))
                {
                    return;
                }
                else if (TboxName.Text.Trim() != "admin")
                {
                    MessageBox.Show("用户名错误");
                    return;
                }
                else if (TboxPassWord.Text.Trim().ToLower() != "123123")
                {
                    MessageBox.Show("密码错误");
                    return;
                }
                else
                {
                    Form1 frmMain = new Form1(2);
                    frmMain.Show();
                    this.Hide();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void TboxPassWord_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                this.button1_Click(sender, e);
            }
        }
    }
}
